﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using compshop.Infrastructure.CompShopDataService;
using compshop.Modules.ListOfEmployees.Presenter;

namespace compshop.Modules.ListOfEmployees.View
{
    /// <summary>
    /// Логика взаимодействия для EmployeeListView.xaml
    /// </summary>
    public partial class EmployeeListView : UserControl, IViewEployeeList
    {
        
        public EmployeeListView()
        {
            InitializeComponent();
            btnAdd.Click += new RoutedEventHandler(btnAdd_Click);
            btnEdit.Click += new RoutedEventHandler(btnEdit_Click);
            lvEmployee.SelectionChanged += new SelectionChangedEventHandler(lvEmployee_SelectionChanged);
        }

        public EmployeeListView(EmployeeListPresenter presenter)
            : this()
        {
            Presenter = presenter;
            Presenter.View = this;
        }

        void btnEdit_Click(object sender, RoutedEventArgs e)
        {
            Presenter.EditEmployee(lvEmployee.SelectedItem as Employee);
        }

        void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            Presenter.AddEmployee();
            lvEmployee.Items.Refresh();
        }
        
        public EmployeeListPresenter Presenter
        {
            get { return DataContext as EmployeeListPresenter; }
            set { DataContext = value; }
        }

        public void SelectedEmployee(int id)
        {
            lvEmployee.SelectedValue = id;
        }
        void lvEmployee_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
             
            Presenter.EmployeeSelectedPublisher((int)((decimal)lvEmployee.SelectedValue));
        }
    }
}
